package com.scqkxx.gamebox.activity.myself;

import android.content.ContentValues;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.util.Log;

import com.android.tu.loadingdialog.LoadingDailog;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.activities.utils.ActivityUtil;
import com.scqkxx.gamebox.activity.myself.loginutils.InputVerificationUtils;
import com.scqkxx.gamebox.activity.myself.loginutils.LoginRequestUtils;
import com.scqkxx.gamebox.activity.myself.loginutils.OnRequestListener;
import com.scqkxx.gamebox.databinding.ActivityChangePsdBinding;
import com.scqkzqtz.base.base.BaseActivity;
import com.scqkzqtz.base.library.utils.ToastUtils;

import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by zsx on 2018/8/14.
 */

public class ChangePsdActivity extends BaseActivity<ActivityChangePsdBinding> {
    private   LoadingDailog dialog;

    @Override
    public int setLayoutId() {
        return R.layout.activity_change_psd;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void init() {

        binding.etPhoneNumber.setTag(InputVerificationUtils.TAG_PHONENUMBER);
//        binding.etPassword.setTag(InputVerificationUtils.TAG_PASSWORD);
//        binding.etCode.setTag(InputVerificationUtils.TAG_SMSCODE);

//        InputVerificationUtils.psdShowHide(binding.checkboxPassword, binding.etPassword);
//        InputVerificationUtils.onPutListener(binding.tvConfirm, binding.etPhoneNumber, binding.etPassword, binding.etCode);

        binding.mTitleView.setOnTitleClickListener((int titleType) -> finish());
        binding.tvConfirm.setOnClickListener(v -> {
            if (InputVerificationUtils.isEmail(binding.etPhoneNumber.getText().toString().trim())) {
                LoginRequestUtils.requestSmsCode(this, LoginRequestUtils.SMSTYPE_FORGET_PASSWORD, binding.etPhoneNumber.getText().toString().trim(), new OnRequestListener() {
                    @Override
                    public void OnVerificationSuccess() {
                        LoadingDailog.Builder loadBuilder=new LoadingDailog.Builder(ChangePsdActivity.this)
                                .setMessage("加载中...")
                                .setCancelable(true)
                                .setCancelOutside(true);
                        dialog=loadBuilder.create();
                        dialog.show();
                    }

                    @Override
                    public void OnVerificationError(String s) {
                        if (dialog != null) dialog.dismiss();
                        ToastUtils.showShortToast(ChangePsdActivity.this, s);
                    }

                    @Override
                    public void OnSuccer(Map<String, Object> map) {
                        if (dialog != null) dialog.dismiss();
                        ContentValues contentValues = new ContentValues();
                        contentValues.put("EmailUrl", binding.etPhoneNumber.getText().toString().trim());
                        ActivityUtil.switchTo(ChangePsdActivity.this ,MailCodeActivity.class ,contentValues);
                    }

                    @Override
                    public void OnError(String s) {
                        if (dialog != null) dialog.dismiss();
                        ToastUtils.showShortToast(ChangePsdActivity.this, s);
                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                    }
                });
            }else{
                ToastUtils.showShortToast(ChangePsdActivity.this, "邮箱输入错误，请稍后再试..");
            }
        });

    }
}
